"""
    面向对象：限制实例的属性和方法
        不能随意的给实例添加方法和属性
"""
import types


class Person:
    __slots__ = ("name","age","eat")

    def __init__(self,name = None):
        self.name = name

def eat(self):
    print("i like eat............")

def drink():
    print("i like drink...........")

person = Person("张三")
# 给对象添加 person 属性
person.age = 10
# 给对象添加 weight 属性,AttributeError: 'Person' object has no attribute 'weight'
# person.weight = 100
# print(person.weight)

# 给实例添加方法
person.eat = types.MethodType(eat,person)
# 异常： 'Person' object has no attribute 'drink'
# person.drink = types.MethodType(drink,person)
person.eat()
# person.drink()